package com.eco.mam.work.request;

import java.util.HashMap;
import java.util.Map;

import javax.swing.text.html.MinimalHTMLWriter;

public class WorkRequestCsvDataValidator {

    public Map validate(String[] strCsvTokens,int lineNo) {
        boolean validate = true;
        StringBuffer missingDataInformation=new StringBuffer();
       
        StringBuffer missingValues=new StringBuffer("The required data are :");
        Map map=null;
        
     /*   if(strCsvTokens.length==12){
        for (int i = 0; i < strCsvTokens.length; i++) {
        
            if ((i== 0) ||(i==1)||(i==2)||(i==3)||(i==5)||(i==6)||(i==8)||(i==9)) {
                
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                }
            }
        }
        }*/
        /*if (strCsvTokens.length!=12){
            
        validate=false;
        }*/
        
        for (int i = 0; i < strCsvTokens.length; i++) {
            switch (i) {
            case 0:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                  missingValues.append("RecordIdentifier,");  
                }

                break;

            case 1:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("TransactionReference, ");
                }

                break;
            case 2:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("ContractReference, ");
                }

                break;
            case 3:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("TransactionTypeCode, ");
                }

                break;

            case 5:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("MTPT_RecordIdentifier, ");
                }

                break;
            case 6:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("MeterPointRefereneNumber, ");
                }

                break;
            case 8:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("AddressTypeCode, ");
                }

                break;
            case 9:
                if (strCsvTokens[i].equals(" ")) {
                    validate = false;
                    missingValues.append("PostCode.");
                }

                break;

            default:
                break;
            }
            if (i == 11) {

                break;
            }
          
             

        }
        if (validate==false) {
            missingDataInformation.append("Some mandatory information is missing for Request No :"+lineNo +"\n");
            missingDataInformation.append(missingValues);
            map=new HashMap();
            map.put("missingData", missingDataInformation);
            map.put("validate", false);
            
        }
        if (validate==true) {
            map=new HashMap();
            map.put("validate", true);
            
        }
        return map;
        
       /* if(validate==false)
        {
            return missingDataInformation;
        }
        if (validate=true) {
            return null;
            
        }*/
    }

}
